import request from "@/utils/request";
import store from "@/store/index";

export function isTenant() {
  return !!store.getters.userInfo.tenantId;
}
export function appVerCode() {
  return store?.getters?.userInfo?.chooseAppVerCode;
}
function deviceContext() {
  return isTenant() ? "/device" : "/ttdevice";
}
function videoContext() {
  return isTenant() ? "/video-video" : "/ttvideo";
}
/*
预置点、巡航计划、看守位、录像计划 原device迁移至video - video
*/
function context() {
  return isTenant() ? "/video-video" : "/ttdevice";
}

//改变树类型
export function updateMapModel(data) {
  return request({
    url: deviceContext() + "/system/user/updateMapModel",
    method: "post",
    data,
  });
}
// 查询视频行政区划树
export function getMonitorTree(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
    data.queryType = 1;
  }
  return request({
    url: deviceContext() + "/video/getMonitorTree",
    method: "post",
    data,
  });
}

// 查询视频树
export function getMonitorTreeTT(data) {
  return request({
    url: "/device/video/getMonitorTree",
    method: "post",
    data,
  });
}
//查询视频组织树
export function getMonitorOrgTree(data) {
  let url = "/video/getMonitorTree";
  if (isTenant()) {
    data.appVerCode = appVerCode();
    data.queryType = 2;
  } else {
    url = "/ttview/device/getMonitorTreeByAreas";
  }
  return request({
    url: deviceContext() + url,
    method: "post",
    data,
  });
}
//查询视频标签树
export function getMonitorLabelTree(data) {
  let url = "/video/getLabelTree";
  if (isTenant()) {
    url = "/video/getMonitorTree";
    data.appVerCode = appVerCode();
    data.queryType = 4;
  }
  return request({
    url: deviceContext() + url,
    method: "post",
    data,
  });
}
export function getTTMonitorLabelTree(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: deviceContext() + "/video/getLabelTree",
    method: "post",
    data,
  });
}

//查询省市县
export function getRegion(data) {
  return request({
    url: "/admin/video/getRegion",
    method: "post",
    data,
  });
}
//获取设备列表
export function queryDevices(data) {
  return request({
    url: deviceContext() + "/video/device/queryDevices",
    method: "post",
    data,
  });
}

//预置位 新增
export function addCameraPreset(data) {
  return request({
    url: context() + "/video/patrol/addCameraPreset",
    method: "post",
    data,
  });
}
//预置位 修改
export function updatePresetInfo(data) {
  return request({
    url: context() + "/video/patrol/updatePresetInfo",
    method: "post",
    data,
  });
}
//预置位 修改名称
export function updatePresetName(data) {
  return request({
    url: context() + "/video/patrol/updatePresetName",
    method: "post",
    data,
  });
}
//预置位 删除
export function delCameraPreset(data) {
  return request({
    url: context() + "/video/patrol/delCameraPreset",
    method: "post",
    data,
  });
}
//预置位 删除检验
export function delCameraPresetCheck(data) {
  return request({
    url: context() + "/video/patrol/delCameraPresetCheck",
    method: "post",
    data,
  });
}
//保存看守位
export function doSetGuard(data) {
  return request({
    url: context() + "/video/patrol/doSetGuard",
    method: "post",
    data,
  });
}

//查询通道
export function queryChannelInfo(data) {
  return request({
    url: "/device/video/device/getChannelInfoForCust",
    method: "post",
    data,
  });
}
//查询通道
export function getChannelInfoForCust(data) {
  return request({
    url: "/ttdevice/ttview/device/listChannelInfoTT",
    method: "post",
    data,
  });
}
//查询权限
export function queryRecordPlanForPage(data) {
  return request({
    url: videoContext() + "/video/query/queryRecordPlanForPage",
    method: "post",
    data,
  });
}
//获取视频存储时长
export function queryRecordPlanStorageDay(data) {
  return request({
    url: deviceContext() + "/video/player/queryRecordPlanStorageDay",
    method: "post",
    data,
  });
}
//保存通道录像计划 批量
export function addRecordPlan(data) {
  return request({
    url: context() + "/video/addRecordPlan",
    method: "post",
    data,
  });
}
//查询权限
export function queryRecordPlanCheck(data) {
  return request({
    url: deviceContext() + "/video/queryRecordPlanCheck",
    method: "post",
    data,
  });
}
//删除通道录像计划
export function deleteRecordPlan(data) {
  return request({
    url: context() + "/video/deleteRecordPlan",
    method: "post",
    data,
  });
}
//新增预案
export function addReservePlan(data) {
  return request({
    url: deviceContext() + "/video/reservePlan/addReservePlan",
    method: "post",
    data,
  });
}
//修改预案
export function updateReservePlan(data) {
  return request({
    url: deviceContext() + "/video/reservePlan/updateReservePlan",
    method: "post",
    data,
  });
}
//查询预案
export function queryReservePlan(data) {
  return request({
    url: deviceContext() + "/video/reservePlan/queryReservePlan",
    method: "post",
    data,
  });
}
//删除预案
export function delReservePlan(data) {
  return request({
    url: deviceContext() + "/video/reservePlan/delReservePlan",
    method: "post",
    data,
  });
}
//设备收藏
export function updatemonitorCollect(data) {
  return request({
    url: "/device/industry/device/addOrCancelCollections",
    method: "post",
    data,
  });
}
//查询摄像机可视域
export function getDeviceModelInfo(data) {
  return request({
    url: "/device/industry/device/getDeviceModelInfo",
    method: "post",
    data,
  });
}
//查询视频屏数设置信息
export function queryScreenConfig(data) {
  return request({
    url: "video-video/video/screenConfig/queryScreenConfig",
    method: "post",
    data,
  });
}
//新增视频屏数设置信息
export function addScreenConfig(data) {
  return request({
    url: "video-video/video/screenConfig/addScreenConfig",
    method: "post",
    data,
  });
}
//更新视频屏数设置信息
export function updateScreenConfig(data) {
  return request({
    url: "video-video/video/screenConfig/updateScreenConfig",
    method: "post",
    data,
  });
}
export function batchDeleteRecordPlan(data) {
  return request({
    url: "video-video/video/batchDeleteRecordPlan",
    method: "post",
    data,
  });
}
//批量停用启用
export function batchStartOrEndRecordPlan(data) {
  return request({
    url: "video-video/video/batchStartOrEndRecordPlan",
    method: "post",
    data,
  });
}
//查询巡航计划暂停恢复信息
export function queryPauseResumePatrolInfo(data) {
  return request({
    url: "video-video/video/patrol/queryPauseResumePatrolInfo",
    method: "post",
    data,
  });
}
//巡航计划暂停恢复
export function pauseResumePatrol(data) {
  return request({
    url: "video-video/video/patrol/pauseResumePatrol",
    method: "post",
    data,
  });
}

//查询摄像机可视域
export function getDeviceVisibleBySite(data) {
  return request({
    url: "/device/industry/device/getDeviceVisibleBySite",
    method: "post",
    data,
  });
}
//物联设备树
export function getIotDeviceTree(query) {
  query.queryType = 4;
  query.needDevice = true;
  query.orderStatus = "1";
  return request({
    url: "/device/deviceCommon/getDeviceAreaTree",
    method: "post",
    data: query,
  });
}
//物联设备配置列表
export function queryIotDeviceConfigList(query) {
  return request({
    url: "/device/iotDeviceConfig/queryIotDeviceConfigList",
    method: "post",
    data: query,
  });
}
//绑定物联设备配置
export function bindIotDeviceConfig(query) {
  return request({
    url: "/device/iotDeviceConfig/bindIotDeviceConfig",
    method: "post",
    data: query,
  });
}
//解绑物联设备配置
export function unbindIotDeviceConfig(query) {
  return request({
    url: "/device/iotDeviceConfig/unbindIotDeviceConfig",
    method: "post",
    data: query,
  });
}
//更换物联设备配置
export function changeIotDeviceConfig(query) {
  return request({
    url: "/device/iotDeviceConfig/changeIotDeviceConfig",
    method: "post",
    data: query,
  });
}
//物联设备数据监测
export function getSensorData(query) {
  return request({
    url: "/device/iotDeviceConfig/getSensorData",
    method: "post",
    data: query,
  });
}
//查询自定义视频树类型下拉列表
export function getDeviceDiySelect(query) {
  return request({
    url: "/device/deviceDiy/getList",
    method: "post",
    data: query,
  });
}

// 自定义设备树 列表
export function getDeviceDiyList(query) {
  return request({
    url: "/device/deviceDiy/getList",
    method: "post",
    data: query,
  });
}
// 自定义树启用、停用
export function updateDeviceDiyStatus(query) {
  return request({
    url: "/device/deviceDiy/updateStatus",
    method: "post",
    data: query,
  });
}
// 自定义设备树详情
export function getDeviceDiyDetail(query) {
  return request({
    url: "/device/deviceDiy/getOriginalDiyTree",
    method: "post",
    data: query,
  });
}
// 自定义设备树新增
export function saveDeviceDiy(query) {
  return request({
    url: "/device/deviceDiy/save",
    method: "post",
    data: query,
  });
}
// 自定义设备树编辑
export function updateDeviceDiy(query) {
  return request({
    url: "/device/deviceDiy/update",
    method: "post",
    data: query,
  });
}
// 自定义设备树
export function getDeviceDiyTree(query) {
  return request({
    url: "/device/deviceDiy/getDiyTree",
    method: "post",
    data: query,
  });
}
// 自定义设备树删除
export function deleteDeviceDiy(query) {
  return request({
    url: "/device/deviceDiy/delete",
    method: "post",
    data: query,
  });
}

/**
 * 10.批量下载录像
 * @param query
 * @returns {AxiosPromise}
 */
export function downloadVideo(query) {
  return request({
    url: "/video-stdu/video/player/downloadVideo",
    method: "post",
    data: query,
  });
}

/**
 * 11、查询录像百分比
 * @param query
 * @returns {AxiosPromise}
 */
export function downloadProcess(query) {
  return request({
    url: "/video-stdu/video/player/downloadProcess",
    method: "post",
    data: query,
  });
}

/**
 * 10、批量停止下载
 * @param query
 * @returns {AxiosPromise}
 */
export function stopDownloadVideo(query) {
  return request({
    url: "/video-stdu/video/player/stopDownloadVideo",
    method: "post",
    data: query,
  });
}

/**
 * 12、录像下载列表
 * @param query
 * @returns {AxiosPromise}
 */
export function recordDownloadList(query) {
  return request({
    url: "/video-video/recordDownload/list",
    method: "post",
    data: query,
  });
}
/**
 * 12.1、删除录像
 * @param query
 * @returns {AxiosPromise}
 */
export function deleteRecordDownload(query) {
  return request({
    url: "/video-video/recordDownload/delete",
    method: "post",
    data: query,
  });
}

/**
 * 查询周边设备
 * @param query
 * //longitude,latitude,radius单位里
 * @returns {*}
 */
export function queryHornByRange(query) {
  let url = "/ttbdm/aroundAnalysisOwn/queryHornDeviceDistanceInfo";
  if (isTenant()) {
    url = "/device/deviceCommon/getDeviceDistanceInfo";
    query.queryType = 5;
  }
  return request({
    url: url,
    method: "post",
    data: query,
  });
}

/**
 * 查询摄像机抓图任务列表
 */
export function querySnapShotList(query) {
  return request({
    url: "/ttvideo/video/playerSnapShot/querySnapShotList",
    method: "post",
    data: query,
  });
}
/**
 * 新增摄像机抓图任务
 */
export function addSnapShot(query) {
  return request({
    url: "/ttvideo/video/playerSnapShot/addSnapShot",
    method: "post",
    data: query,
  });
}
/**
 * 编辑摄像机抓图任务
 */
export function editSnapShot(query) {
  return request({
    url: "/ttvideo/video/playerSnapShot/editSnapShot",
    method: "post",
    data: query,
  });
}
/**
 * 校验抓图认识是否正在执行
 */
export function checkTaskStatus(query) {
  return request({
    url: "/ttvideo/video/playerSnapShot/checkTaskStatus",
    method: "post",
    data: query,
  });
}
/**
 * 获取新增抓图任务名称
 */
export function getDefTaskName(query) {
  return request({
    url: "/ttvideo/video/playerSnapShot/getDefTaskName",
    method: "get",
    data: query,
  });
}
/**
 * 获取新增抓图任务名称
 */
export function delSnapShot(query) {
  return request({
    url: "/ttvideo/video/playerSnapShot/delSnapShot",
    method: "post",
    data: query,
  });
}
/**
 * 获取抓图任务详情
 */
export function getSnapShot(query) {
  return request({
    url: "/ttvideo/video/playerSnapShot/getSnapShot",
    method: "post",
    data: query,
  });
}
/**
 * 获取客户设备权限
 */
export function getDevicePermission(data) {
  return request({
    url: "/device/video/device/checkDeviceOptAuth",
    method: "post",
    data,
  });
}
/**
 * 开启电子围栏发送心跳
 */
export function sendHeartBeat(data) {
  return request({
    url: "/outdata/presetArrivalNotice/sendHeartBeat",
    method: "post",
    data,
  });
}
